/***********************************************************
 * Product Name: ExcelQuicker
 * Copyright (c)2005, Eunge
 * Author: Eunge
 * Web Site: www.eudev.net
 * Mail/MSN: eudev.net@yeah.net
 * ********************************************************/
using System;

namespace ExcelQuicker.Framework
{
	/// <summary>
	/// Basic style setting, etc font size, family, color, and so on. Additional, we can set hyperlink also.
	/// </summary>
	[Serializable]
	public class EQRangeStyle: EQStyleBase
	{
		private int mSize = DefaultInt;
		private string mFamily = "";
		private int mColor = DefaultInt;
		private int mBackColor = DefaultInt;
		private EQBool mBond = EQBool.Default;
		private EQBool mUnderline = EQBool.Default;
		private EQBool mItalic = EQBool.Default;
		private string mHyperlink = "";

		/// <summary>
		/// Set/Get back color
		/// </summary>
		public int BackColor
		{
			get
			{
				return this.mBackColor;
			}
			set
			{
				this.mBackColor = EQKit.CheckColorIndex(value);
			}
		}

		/// <summary>
		/// Set/Get whether is bond
		/// </summary>
		public bool Bond
		{
			get
			{
				return (this.mBond==EQBool.True)?true:false;
			}
			set
			{
				this.mBond = value?EQBool.True:EQBool.False;
			}
		}

		/// <summary>
		/// Set/Get fore color
		/// </summary>
		public int Color
		{
			get
			{
				return this.mColor;
			}
			set
			{
				this.mColor = EQKit.CheckColorIndex(value);
			}
		}

		/// <summary>
		/// Set/Get font family
		/// </summary>
		public string Family
		{
			get
			{
				return this.mFamily;
			}
			set
			{
				this.mFamily = value.Trim();
			}
		}

		/// <summary>
		/// Set/Get whether is italic
		/// </summary>
		public bool Italic
		{
			get
			{
				return (this.mItalic==EQBool.True)?true:false;
			}
			set
			{
				this.mItalic = value?EQBool.True:EQBool.False;
			}
		}

		/// <summary>
		/// Set/Get font size
		/// </summary>
		public int Size
		{
			get
			{
				return this.mSize;
			}
			set
			{
				this.mSize = EQKit.CheckFontSize(value);
			}
		}

		/// <summary>
		/// Set/Get whether is underline
		/// </summary>
		public bool Underline
		{
			get
			{
				return (this.mUnderline==EQBool.True)?true:false;
			}
			set
			{
				this.mUnderline = value?EQBool.True:EQBool.False;
			}
		}

		/// <summary>
		/// Set/Get hyper link
		/// </summary>
		public string Hyperlink
		{
			get
			{
				return mHyperlink;
			}
			set
			{
				mHyperlink = value.Trim();
			}
		}


		/// <summary>
		///  Output this style on excel document
		/// </summary>
		/// <param name="objRange"></param>
		protected internal override void Output(Excel.Range objRange)
		{
			this.Output(objRange.Font, objRange.Interior, objRange);

			if(this.mHyperlink != null && this.mHyperlink.Length != 0)
				objRange.Worksheet.Hyperlinks.Add(objRange,mHyperlink,this.Missing,this.Missing,this.Missing);
		}

		/// <summary>
		/// Output this style. This function called by conditional style output.
		/// </summary>
		/// <param name="objFont"></param>
		/// <param name="objInterior"></param>
		/// <param name="objRange"></param>
		protected internal void Output(Excel.Font objFont, Excel.Interior objInterior, Excel.Range objRange)
		{
			this.DoBeforeOperationEvent(objRange);

			if(this.mSize != DefaultInt)
				objFont.Size = this.mSize;

			if(this.mFamily != null && this.mFamily.Length != 0)
				objFont.Name = this.mFamily;

			if(this.mColor != DefaultInt)
				objFont.ColorIndex = this.mColor;

			if(this.mBond == EQBool.True)
				objFont.Bold = true;
			else if(this.mBond == EQBool.False)
				objFont.Bold = false;

			if(this.mUnderline == EQBool.True)
				objFont.Underline = true;
			else if(this.mUnderline == EQBool.False)
				objFont.Underline = false;

			if(this.mItalic == EQBool.True)
				objFont.Italic = true;
			else if(this.mItalic == EQBool.False)
				objFont.Italic = false;

			if(this.mBackColor != DefaultInt)
				objInterior.ColorIndex = this.mBackColor;

			this.DoAfterOperationEvent(objRange);
		}
	}
}
